package com.dao;

import java.io.Serializable;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import com.model.ClienteModel;

public class ClienteDao extends DefaultDao implements Serializable{
	public void salvar(ClienteModel pessoa){
		EntityManager em = getEntityManager();
		try{
			em.getTransaction().begin();
			em.persist(pessoa);
			em.getTransaction().commit();
		}catch (Exception e) {
			em.getTransaction().rollback();
		}
	}
	public void novaPessoa(String nome){
		ClienteModel p = new ClienteModel();
		p.setNome(nome);
		salvar(p);
	}
	public List<ClienteModel> getClientes(){
		EntityManager em = getEntityManager();
		try{
			Query q = em.createQuery("select e from ClienteModel e");
			return q.getResultList();
		}
		finally{
			em.close();
		}
	}
}